import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)


const route = new Router({
    routes: [{
            path: '/',
            name: 'login',
            component: () =>
                import ('@/components/login/login')
        }, //登录界面//

        {
            path: '/change_position',
            name: 'change_position',
            component: () =>
                import ('@/components/login/change_position')
        }, //切换身份

        {
            path: '/home',
            name: 'home',
            component: () =>
                import ('@/components/home')
        }, //主页

        {
            path: '/project',
            name: 'project',
            component: () =>
                import ('@/components/project/project')
        }, //项目

        {
            path: '/financial',
            name: 'financial',
            component: () =>
                import ('@/components/financial/financial')
        }, //财务

        {
            path: '/other',
            name: 'other',
            component: () =>
                import ('@/components/other/other')
        }, //其他

        {
            path: '/tables',
            name: 'tables',
            component: () =>
                import ('@/components/tables/tables')
        }, //常用表格

        {
            path: '/summary_detail',
            name: 'summary_detail',
            component: () =>
                import ('@/components/tables/summaryDetail')
        }, //汇总详情

        {
            path: '/system',
            name: 'system',
            component: () =>
                import ('@/components/system/system')
        }, //规章制度

        {
            path: '/signin',
            name: 'sign',
            component: () =>
                import ('@/components/sign/sign')
        }, //签到/签退
        //设置组件子路由
        {
            path: '/setting',
            name: 'setting',
            component: () =>
                import ('@/components/setting/setting')
        }, //设置

        //echart
        {
            path: '/chart1',
            name: 'chart1',
            component: () =>
                import ('@/components/echart/chart1')
        },

        {
            path: '/chart2',
            name: 'chart2',
            component: () =>
                import ('@/components/echart/chart2')
        },

        // 时间线
        {
            path: '/timer',
            name: 'timer',
            component: () =>
                import ('@/components/timer/timer')
        },

        //sass test
        {
            path: '/test',
            name: 'test',
            component: () =>
                import ('@/components/test/test1')
        },
        //流程设置
        {
            path: '/work/work_set',
            name: 'work_set',
            component: () =>
                import ('@/components/workflow/work_set')
        },

        {
            path: '/project_list',
            name: 'project_list',
            component: () =>
                import ('@/components/project/project_list'),
        }, //项目数据

        {
            path: '/project_lx/edit',
            name: 'edit_project_lx',
            component: () =>
                import ('@/components/project/project_edit_lx')
        }, //编辑项目详情

        {
            path: '/project_ys/edit',
            name: 'edit_project_ys',
            component: () =>
                import ('@/components/project/project_edit_ys')
        }, //编辑预算详情

        {
            path: '/project_js/edit',
            name: 'edit_project_js',
            component: () =>
                import ('@/components/project/project_edit_js')
        }, //编辑结算详情

        {
            path: '/financial/list',
            name: 'financialList',
            component: () =>
                import ('@/components/financial/financialList')
        }, //财务列表

        {
            path: '/financial/edit',
            name: 'financeDetail',
            component: () =>
                import ('@/components/financial/financeDetail')
        }, //财务编辑

        {
            path: '/admin',
            name: 'admin',
            component: () =>
                import ('@/components/admin/admin')
        }, //

        {
            path: '/administrative',
            name: 'administrative',
            component: () =>
                import ('@/components/admin/adminList')
        }, //行政报销

        {
            path: '/adminDetail',
            name: 'adminDetail',
            component: () =>
                import ('@/components/admin/adminDetail')
        }, //行政报销详情

        {
            path: '/sign',
            name: 'personnel',
            component: () =>
                import ('@/components/personnel/personnel'),
            children: [{
                path: '/detail',
                name: 'personnelDetail',
                component: () =>
                    import ("@/components/personnel/personnelDetail")
            }, ],
        }, //人事
        //邮箱
        {
            path: '/email',
            name: 'email',
            component: () =>
                import ('@/components/email/email')
        },

        {
            path: '/rules',
            name: 'rules',
            component: () =>
                import ('@/components/rules/rules')
        },


        {
            path: '/purchase',
            name: 'purchase',
            component: () =>
                import ('@/components/purchase/purchaseHome')
        }, //采购

        {
            path: '/purchase/orderRequest',
            component: () =>
                import ('@/components/purchase/requiredOrder')
        }, //订单需求

        {
            path: '/purchase/detail',
            component: () =>
                import ('@/components/purchase/purchaseDetail')
        }, //公司采购详情


        {
            path: '/supplier',
            component: () =>
                import ('@/components/supplier/supplierHome')
        }, //供应商页面

        {
            path: '/supplier/projectRequest',
            component: () =>
                import ('@/components/supplier/projectRequest')
        }, //供应商页面

        {
            path: '/supplier/detail',
            component: () =>
                import ('@/components/supplier/requestDetail')
        }, //供应商详情页面


      {
        path: '/note',
        component: () =>
          import ('@/components/note/note')
      }, //供应商详情页面



    ]
})

//守护路由
route.beforeEach((to, from, next) => {
    let isAuthenticated = sessionStorage.getItem('userinfo') === null
    if (to.name !== 'login' && isAuthenticated) {
        next({ name: 'login' })
    } else {
        next()
    }
    let currentName = to.name;
    let backImg = 'background002.jpg';
    if (currentName == 'login'){
      backImg = 'background001.png';
    }else if(currentName == 'home' || currentName == 'change_position'){
      backImg = 'background002.png';
    }else if(currentName == 'financialList'){backImg = 'cw_bg.jpg';}else{
      backImg = 'background003.png';
    }
    document.body.style.background = "url(../../static/img/" + backImg + ") no-repeat 0 center";
    document.body.style.backgroundSize = "100% 100%";

})


export default route
